package thread.java20230110;

class Result{
    private int sum;

    public int getSum() {
        return sum;
    }

    public void setSum(int sum) {
        this.sum = sum;
    }
}
public class Demo49 {
    public static void main(String[] args) throws InterruptedException {
        Result result = new Result();
        Thread thread = new Thread(()->{
            int sum = 0;
            for (int i = 1; i <= 1000; i++) {
                sum += i;
            }
            result.setSum(sum);
        });
        thread.start();
        //main线程需要获取sum, 通过共享变量的方式来获取
        thread.join();
        System.out.println(result.getSum());
    }
}
